package com.xtayfjpk.thrift.test.server;

import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.server.THsHaServer;
import org.apache.thrift.server.TServer;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TNonblockingServerSocket;

import com.xtayfjpk.thrift.test.service.HelloWorldService;
import com.xtayfjpk.thrift.test.service.HelloWorldService.Iface;
import com.xtayfjpk.thrift.test.service.HelloWorldServiceImpl;

public class THsHaHelloWorldServer {

	public static void main(String[] args) throws Exception {
		TProcessor tProcessor = new HelloWorldService.Processor<Iface>(new HelloWorldServiceImpl());
		
		TNonblockingServerSocket serverSocket = new TNonblockingServerSocket(8090);
		THsHaServer.Args tArgs = new THsHaServer.Args(serverSocket);
		
		tArgs.processor(tProcessor);
		// 半同步半异步的服务端模型，需要指定为： TFramedTransport 数据传输的方式。
		tArgs.transportFactory(new TFramedTransport.Factory());
		tArgs.protocolFactory(new TCompactProtocol.Factory());
		
		TServer server = new THsHaServer(tArgs);
		
		server.serve();
	}

}
